home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / tex / td187src.lzh / PICTOMET.I < prev    next >
Text File  |  1991-12-14  |  33KB  |  1,083 lines

  1. IMPLEMENTATION MODULE PicToMeta;
  2. (* Wandelt Graphikfiles in's       *)
  3. (* Metafont-Format                 *)
  4. (* JP 16/11/90 18:30               *)
  5. (* Letzte Änderung: 01/12/90 14:26 *)
  6. (* Letzte Änderung: 17/03/91 11:08 *)
  7.  
  8. FROM Dialoge     IMPORT BusyStart, BusyEnd, ChangePicRes, GetFontRes;
  9. FROM Diverses    IMPORT NumAlert;
  10. FROM FileIO      IMPORT Rewrite, WriteLn, Close, Reset, EOF, ReadChar;
  11. FROM SYSTEM      IMPORT ADDRESS , ADR;
  12. FROM Storage     IMPORT ALLOCATE , DEALLOCATE ;
  13. FROM Types       IMPORT ObjectPtrTyp, sourceformat, targetformat;
  14.  
  15. IMPORT CommonData;
  16. IMPORT GetFile;
  17. IMPORT MagicStrings ;
  18. IMPORT MagicSys ;
  19. IMPORT mtAlerts;
  20. IMPORT Variablen;
  21. (**
  22. IMPORT RTD;
  23. **)
  24.  
  25. TYPE LinePtr     = POINTER TO LineRec;
  26.      LineRec     = RECORD
  27.                      start, end, line, depth : INTEGER;
  28.                      Prev, Next : LinePtr;
  29.                    END;
  30. VAR
  31.     RdHandle          : INTEGER;
  32.     WtHandle          : INTEGER;
  33.     OptimizeMode      : BOOLEAN;
  34.     MetafontMode      : targetformat;
  35.     FirstPtr          : LinePtr;
  36.     startx            : INTEGER;
  37.     endx              : INTEGER;
  38.     Xmul, Ymul        : INTEGER;
  39.     XYswap            : BOOLEAN; (* fürs PAC-Format benötigt *)
  40.  
  41.     DebugLevel        : CARDINAL;
  42.  
  43.  
  44. PROCEDURE ggT(x, y : INTEGER) : INTEGER;
  45. VAR a, b, r : INTEGER;
  46. BEGIN
  47.   a := x;       (* Euklidischer Algorithmus *)
  48.   b := y;
  49.   REPEAT
  50.     r := b MOD a;
  51.     b := a;
  52.     a := r;
  53.   UNTIL r=0;
  54.   RETURN b;
  55. END ggT;
  56.  
  57. (**
  58. PROCEDURE AppendChar(c : CHAR; VAR target : ARRAY OF CHAR);
  59. VAR temp : ARRAY [0..1] OF CHAR;
  60. BEGIN
  61.   temp[0] := c;
  62.   temp[1] := 0C;
  63.   MagicStrings.Append(temp, target);
  64. END AppendChar;
  65. **)
  66.  
  67. PROCEDURE GetOutFileName(     input : ARRAY OF CHAR;
  68.                          VAR output : ARRAY OF CHAR);
  69. VAR i : INTEGER;
  70. BEGIN
  71.   MagicStrings.Assign( input, output );
  72.   CASE MetafontMode OF
  73.     metafont: i := 4; |
  74.     tex :     i := 2; |
  75.     gfpk:     i := 10; |
  76.    ELSE
  77.     i := 0;
  78.   END;
  79.   IF i>0 THEN
  80.     GetFile.ReplaceExtension(output, CommonData.Extensions[i]);
  81.   END;
  82.   GetFile.RemovePath(output);
  83.   CASE MetafontMode OF
  84.     metafont : IF CommonData.MetaPath[0]<>0C THEN
  85.              MagicStrings.Insert(CommonData.MetaPath, output, 0);
  86.            END; |
  87.     tex  : IF CommonData.LaTeXPath[0]<>0C THEN
  88.              MagicStrings.Insert(CommonData.LaTeXPath, output, 0);
  89.            END; |
  90.     gfpk : IF CommonData.GFPKPath[0]<>0C THEN
  91.              MagicStrings.Insert(CommonData.GFPKPath, output, 0);
  92.            END; |
  93.    ELSE
  94.   END;
  95. END GetOutFileName;
  96.  
  97. PROCEDURE WriteMetaProlog(xo, yo, X, Y : INTEGER;
  98.                                   info : ARRAY OF CHAR);
  99. (*  X,  Y : Zahl der Spalten und Zeilen *)
  100. (* xo, yo : Größe eines Pixels in µm *)
  101. VAR Line, String : ARRAY [0..127] OF CHAR;
  102.     Comment      : ARRAY [0..1] OF CHAR;
  103. BEGIN
  104.   Comment := '%';
  105.   WriteLn ( WtHandle, Comment ) ;
  106.   WriteLn ( WtHandle, '% Graphic-font-file  (created by TeX-Draw, JP-90)');
  107.   IF OptimizeMode THEN
  108.     WriteLn ( WtHandle,
  109.      '% I tried to minimize the number of commands (not very well I fear).');
  110.    ELSE
  111.     WriteLn ( WtHandle,
  112.      '% There are no optimizations at all (well just one)');
  113.   END;
  114.   WriteLn ( WtHandle, info ) ;
  115.   WriteLn ( WtHandle, Comment ) ;
  116.   WriteLn ( WtHandle, 'mode_setup;' ) ;
  117.   WriteLn ( WtHandle, 'font_identifier:="TeXDraw-Picture";');
  118.   WriteLn ( WtHandle, 'font_coding_scheme:="TeXDraw-Conversion";');
  119.  
  120.   WriteLn ( WtHandle, Comment ) ;
  121.   WriteLn ( WtHandle, "% This file contains just one graphic, so we don't need to");
  122.   WriteLn ( WtHandle, '% specify values for fontdimen 1..7 (at least I hope so).');
  123.   WriteLn ( WtHandle, Comment ) ;
  124.  
  125.   Line := 'xu# := ';  Variablen.NumberToStr(xo, String);
  126.   MagicStrings.Append( String, Line);
  127.   MagicStrings.Append( ' * 0.001 * mm#;' , Line);
  128.   WriteLn ( WtHandle, Line);
  129.   Line := 'yu# := ';  Variablen.NumberToStr(yo, String);
  130.   MagicStrings.Append( String, Line);
  131.   MagicStrings.Append( ' * 0.001 * mm#;' , Line);
  132.   WriteLn ( WtHandle, Line);
  133.  
  134.   Line := 'symb_w#:=';   Variablen.NumberToStr(X, String);
  135.   MagicStrings.Append( String, Line);
  136.   MagicStrings.Append( ' * xu#;', Line);
  137.   WriteLn ( WtHandle, Line);
  138.   Line := 'symb_h#:=';   Variablen.NumberToStr(Y, String);
  139.   MagicStrings.Append( String, Line);
  140.   MagicStrings.Append( ' * yu#;', Line);
  141.   WriteLn ( WtHandle, Line);
  142.   WriteLn ( WtHandle, 'font_size symb_h#;');
  143.   WriteLn ( WtHandle, 'define_pixels(xu, yu);');
  144.   WriteLn ( WtHandle, Comment);
  145.  
  146.   Line := 'beginchar(';
  147.   Variablen.NumberToStr(CommonData.MetaPAscii, String);
  148.   MagicStrings.Append( String, Line);
  149.  
  150.   MagicStrings.Append(', symb_w#, symb_h#, 0); "The picture', Line);
  151.   IF (CommonData.MetaPAscii>=32) AND (CommonData.MetaPAscii<127) THEN
  152.     String    := ' (?)';
  153.     String[2] := CHR(CommonData.MetaPAscii);
  154.     MagicStrings.Append( String, Line);
  155.   END;
  156.   MagicStrings.Append('.";', Line);
  157.  
  158.   WriteLn ( WtHandle, Line );
  159.   WriteLn ( WtHandle, 'pickup pensquare xscaled xu yscaled yu;');
  160. END WriteMetaProlog;
  161.  
  162. (**********************************************************)
  163.  
  164. PROCEDURE WriteTeXProlog(xo, yo, X, Y : INTEGER;
  165.                                  info : ARRAY OF CHAR);
  166. (*  X,  Y : Zahl der Spalten und Zeilen *)
  167. (* xo, yo : Größe eines Pixels in µm *)
  168. VAR Line, String : ARRAY [0..127] OF CHAR;
  169.     Comment      : ARRAY [0..1] OF CHAR;
  170.     ggTVal       : INTEGER;
  171. BEGIN
  172.   Comment := '%';
  173.   WriteLn ( WtHandle, Comment ) ;
  174.   WriteLn ( WtHandle, '% Graphic-TeX-file  (created by TeX-Draw, JP-90)');
  175.   IF OptimizeMode THEN
  176.     WriteLn ( WtHandle,
  177.      '% I tried to minimize the number of commands (not very well I fear).');
  178.    ELSE
  179.     WriteLn ( WtHandle,
  180.      '% There are no optimizations at all (well just one)');
  181.   END;
  182.   WriteLn ( WtHandle, info ) ;
  183.   WriteLn ( WtHandle, Comment ) ;
  184.   WriteLn ( WtHandle, '\newdimen\mum \mum=0.001mm' ) ;
  185.  
  186.   ggTVal := ggT(xo, yo);
  187.   Xmul   := xo DIV ggTVal;
  188.   Ymul   := yo DIV ggTVal;
  189.  
  190.   Line := '\newdimen\xu \xu=';  Variablen.NumberToStr(xo, String);
  191.   MagicStrings.Append( String, Line);
  192.   MagicStrings.Append( '\mum' , Line);
  193.   WriteLn ( WtHandle, Line);
  194.  
  195.   Line := '\newdimen\yu \yu=';  Variablen.NumberToStr(yo, String);
  196.   MagicStrings.Append( String, Line);
  197.   MagicStrings.Append( '\mum' , Line);
  198.   WriteLn ( WtHandle, Line);
  199.  
  200.   Line := "\setlength{\unitlength}{";
  201.   Variablen.NumberToStr(ggTVal, String); MagicStrings.Append( String, Line);
  202.   MagicStrings.Append( '\mum}' , Line);
  203.   WriteLn ( WtHandle, Line) ;
  204.  
  205.   Line := '\begin{picture}(';
  206.   Variablen.NumberToStr(X * Xmul, String); MagicStrings.Append( String, Line);
  207. (*  AppendChar(',', Line);*)
  208.   MagicStrings.Append(',', Line);
  209.   Variablen.NumberToStr(Y * Ymul, String); MagicStrings.Append( String, Line);
  210. (*  AppendChar(')', Line);*)
  211.   MagicStrings.Append(')', Line);
  212.   WriteLn ( WtHandle, Line);
  213. END WriteTeXProlog;
  214.  
  215. (**********************************************************)
  216.  
  217. PROCEDURE WriteMetaEpilog;
  218. VAR Line : ARRAY [0..127] OF CHAR;
  219. BEGIN
  220.   WriteLn ( WtHandle, 'endchar;  % Pooh, this was lot of work...');
  221.   WriteLn ( WtHandle, 'end.');
  222. END WriteMetaEpilog;
  223.  
  224. (**********************************************************)
  225.  
  226. PROCEDURE WriteTeXEpilog;
  227. BEGIN
  228.   WriteLn ( WtHandle, '\end{picture} % Pooh, this was lot of work...');
  229. END WriteTeXEpilog;
  230.  
  231. (**********************************************************)
  232.  
  233. PROCEDURE DoLine(start, end, second, depth : INTEGER);
  234. VAR Start, End, Third : INTEGER;
  235.     LowY, LowX        : INTEGER;
  236.     temp,
  237.     Line, number : ARRAY [0..127] OF CHAR;
  238.  
  239.   PROCEDURE AddNum(a, b    : INTEGER;
  240.                    REF txt : ARRAY OF CHAR);
  241.   BEGIN
  242.     IF XYswap THEN
  243.       Variablen.NumberToStr(a, number);
  244.      ELSE
  245.       Variablen.NumberToStr(b, number);
  246.     END;
  247.     MagicStrings.Append( number, Line);
  248.     MagicStrings.Append( txt, Line);
  249.   END AddNum;
  250.  
  251.   PROCEDURE AddFill(a, b    : INTEGER;
  252.                     minus   : BOOLEAN;
  253.                     REF txt : ARRAY OF CHAR);
  254.   VAR i : INTEGER;
  255.   BEGIN
  256.     IF XYswap THEN
  257.       i